package com.lantu.sys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.lantu.sys.entity.Semester;
import com.lantu.sys.mapper.SemesterMapper;
import com.lantu.sys.service.SemesterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

// 定义service实现类
@Service
public class SemesterServiceImpl extends ServiceImpl<SemesterMapper, Semester> implements SemesterService {

    @Override
    public IPage<Semester> getSemesterByOpr(Page<Semester> pageParam, Semester query) {
        QueryWrapper<Semester> SemesterQueryWrapper = new QueryWrapper<>();

        if(!StringUtils.isEmpty(query.getAcademicYear())){
            SemesterQueryWrapper.like("academic_year",query.getAcademicYear());
        }
        SemesterQueryWrapper.orderByAsc("id");
        Page<Semester> semesterPage = baseMapper.selectPage(pageParam, SemesterQueryWrapper);
        return semesterPage;
    }

    @Override
    public List<Semester> getlist() {
        QueryWrapper<Semester> semesterQueryWrapper = new QueryWrapper<>();
        semesterQueryWrapper.select("DISTINCT academic_year");
        return baseMapper.selectList(semesterQueryWrapper);

    }

    @Override
    public List<Semester> getByName(Semester semester) {
        QueryWrapper<Semester> semesterQueryWrapper = new QueryWrapper<>();
        semesterQueryWrapper.eq("title_name",semester.getTitleName());
        return baseMapper.selectList(semesterQueryWrapper);
//        return null;
    }


}
